import 'package:flutter/material.dart';
import 'package:flutter_cwhisky/component/text_view.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../common/style/colors.dart';
import '../../../component/base/base_state_less_view.dart';
import 'home_logic.dart';

class HomePage extends BaseStateLessView<HomeLogic> {
  HomePage({super.key});

  _appBar() {
    return Column(
      children: [
        _searchBar(),
        _getTabBar(),
      ],
    );
  }

  _searchBar() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 15.w, vertical: 5.h),
      child: Row(
        children: [
          Expanded(
            child: Container(
              height: 34.h,
              decoration: BoxDecoration(borderRadius: BorderRadius.circular(17.r), color: AppColors.white),
              child: Row(
                children: [
                  Padding(padding: EdgeInsets.symmetric(horizontal: 16.w), child: Icon(
                    Icons.search,
                    size: 14.r,
                  ) ,),
                  TextView(
                    text: '搜索一下',
                    fontColor: AppColors.colorCc,
                    fontSize: 14.sp,
                  )
                ],
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.only(left: 16.w),
            child: Image.asset(
              controller.messageIcon,
              width: 17.r,
              height: 17.w,
            ),
          )
        ],
      ),
    );
  }

  _getTabBar() {
    var map = controller.tiles
        .map((e) =>
        Tab(
          text: e,
        ))
        .toList();
    return TabBar(
      indicatorPadding: const EdgeInsets.symmetric(horizontal: 6, vertical: 8),
      indicatorSize: TabBarIndicatorSize.label,
      indicatorColor: AppColors.primary,
      labelStyle: TextStyle(color: AppColors.colorTextMain, fontSize: 18.sp, fontWeight: FontWeight.w500),
      labelColor: AppColors.colorTextMain,
      unselectedLabelStyle: TextStyle(color: AppColors.colorTextSub, fontSize: 16.sp, fontWeight: FontWeight.w300),
      unselectedLabelColor: AppColors.colorTextSub,
      tabs: map,
      padding: EdgeInsets.zero,
      indicator: UnderlineTabIndicator(
          borderRadius: BorderRadius.circular(4),
          borderSide: const BorderSide(width: 2.0, color: AppColors.colorTextMain)),
      labelPadding: EdgeInsets.symmetric(horizontal: 12.w),
      isScrollable: true,
      controller: controller.tabController,
      splashBorderRadius: BorderRadius.circular(4.r),
    );
  }

  @override
  Widget buildContent(BuildContext context) {
    var top = MediaQuery
        .of(context)
        .padding
        .top;
    return Scaffold(
      backgroundColor: AppColors.colorF7,
      body: Stack(
        children: [
          IgnorePointer(
            child: Container(
              height: 244.h,
              width: double.maxFinite,
              decoration: const BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    colors: [
                      Color(0xffFFEFDB),
                      Color(0xffFFF9F0),
                      Color(0xffFFEFE5),
                      Color(0xffF7F7F7),
                    ],
                  )),
            ),
          ),
          Column(
            children: [
              Container(
                child: _appBar(),
                margin: EdgeInsets.only(top: top),
              ),
              Expanded(
                  child: TabBarView(
                    controller: controller.tabController,
                    children: controller.fragments,
                  ))
            ],
          ),
        ],
      ),
    );
  }
}
